package entity

//公共消息
type Cmd struct {
	Cmd string `json:"cmd"`
}

// Register 注册消息
type Register struct {
	Cmd
	Data struct {
		Key   string `json:"key"`
		Name  string `json:"name"`
		Color string `json:"color"`
	} `json:"data"`
}

//设置颜色
type Color struct {
	Cmd
	Data string `json:"data"`
}

//加速度
type AccSpeed struct {
	Cmd
	Data int16 `json:"data"`
}

//坦克转向 tankTurn
type TankTurn struct {
	Cmd
	Data bool `json:"data"`
}

//炮塔转向
type GunTurn struct {
	Cmd
	Data bool `json:"data"`
}

//================func 函数方法=========================================

//注册用户
func GetRegister(name, key string, color string) Register {
	if key == "" || name == "" || color == "" {
		key = "zhangweixing"
		name = "zhangweixing"
		color = "#FF7F00"
	}
	return Register{
		Cmd: Cmd{
			Cmd: "register",
		},
		Data: struct {
			Key   string `json:"key"`
			Name  string `json:"name"`
			Color string `json:"color"`
		}{Key: key, Name: name, Color: color},
	}
}

//坦克颜色
func GetColor(color string) Color {
	if color == "" {
		color = "#34ff4d"
	}
	return Color{
		Cmd: Cmd{
			Cmd: "color",
		},
		Data: color,
	}
}

//坦克加速度
func GetAccSpeed(speed int16) AccSpeed {
	return AccSpeed{
		Cmd: Cmd{
			Cmd: "accSpeed",
		},
		Data: speed,
	}
}

//坦克转向 true 顺时针 false 逆时针
func GetTankTurn(turn bool) TankTurn {
	return TankTurn{
		Cmd: Cmd{
			Cmd: "tankTurn",
		},
		Data: turn,
	}
}

//坦克转向停止 tankTurnStop
func GetTankTurnStop() Cmd {
	return Cmd{
		Cmd: "tankTurnStop",
	}
}

//炮塔转向  true 顺时针 false 逆时针
func GetGunTurn(turn bool) GunTurn {
	return GunTurn{
		Cmd: Cmd{
			Cmd: "gunTurn",
		},
		Data: turn,
	}
}

//炮塔转向停止
func GetGunTurnStop() Cmd {
	return Cmd{
		Cmd: "gunTurnStop",
	}
}

//发射炮弹
func GetShot() Cmd {
	return Cmd{
		Cmd: "shot",
	}
}
